package hedron.db;

import static hedron.Application.log;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.logging.Level;

class DBSchema {

	public static void createDBSchema(DBManager DB) {
		HashSet<String> schemaTables = new HashSet<String>();
		Connection conn = DB.getConnection();

		try {
			if (conn != null) {
				org.h2.fulltext.FullText.init(conn);
				ResultSet rs = DB.query(conn,
						"select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME like 'H%' UNION "
					  + "select SEQUENCE_NAME from INFORMATION_SCHEMA.SEQUENCES ");
				if (rs != null) {
					while (rs.next()) {
						schemaTables.add(rs.getString(1));
					}
					rs.close();
				}
			}
			conn.setAutoCommit(true);

			// create schema
			createGlobalSequence(schemaTables, DB, conn);
			createUsersTables(schemaTables, DB, conn);
			createContactsTypes(schemaTables, DB, conn);
			createContactsTable(schemaTables, DB, conn);
			createCustomerComments(schemaTables, DB, conn);
			createStockGroups(schemaTables, DB, conn);
			createStockTable(schemaTables, DB, conn);
			createGroupingStocks(schemaTables, DB, conn);
			createStoreDesc(schemaTables, DB, conn);
			createStoreTable(schemaTables, DB, conn);
			createInvoiceTable(schemaTables, DB, conn);
			createSaleTable(schemaTables, DB, conn);
			createDestoredTable(schemaTables, DB, conn);
			createSettingsTable(schemaTables, DB, conn);

			// Add migrations here

			// clear cache
			schemaTables.clear();
		} catch (SQLException e) {
			log.log(Level.WARNING, "createDBSchema problem", (Throwable) e);
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {}
		}
	}

	protected static void createGlobalSequence(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HGLOBAL_SEQ")) {
			// SELECT NEXT VALUE FOR HGLOBAL_SEQ
			DB.ddlQuery(conn, "CREATE SEQUENCE if not exists HGLOBAL_SEQ START WITH 1000");
			DB.ddlQuery(conn, "COMMENT ON SEQUENCE HGLOBAL_SEQ IS '\u0413\u043b\u043e\u0431\u0430\u043b\u0435\u043d \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u043d\u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u0437\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438'");
		}
	}

	protected static void createUsersTables(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HUSER")) {
			DB.ddlQuery(conn, "create table if not exists HUSER"
					+ "("
	                + "	USER_ID int not null primary key hash,"
					+ "	U_FULLNAME varchar_ignorecase not null,"
					+ "	U_NAME varchar_ignorecase not null,"
					+ "	U_PASS varchar_ignorecase not null,"
					+ "	U_ACCESS int not null"
					+ ")");
			DB.ddlQuery(conn,
					"COMMENT ON TABLE HUSER IS '\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0432\u0441\u0438\u0447\u043a\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438, \u043f\u044a\u043b\u043d\u0438\u0442\u0435 \u0438\u043c \u0438\u043c\u0435\u043d\u0430, \u0438 \u043f\u0440\u0430\u0432\u0430\u0442\u0430 \u043a\u043e\u0438\u0442\u043e \u0438\u043c\u0430\u0442 \u043d\u0430\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HUSER.U_ACCESS IS '\u041f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0434\u043e\u0441\u0442\u044a\u043f'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HUSER.U_FULLNAME IS '\u041f\u044a\u043b\u043d\u043e \u0438\u043c\u0435 \u043d\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HUSER.U_NAME IS '\u0438\u043c\u0435 \u0437\u0430 \u0432\u043b\u0438\u0437\u0430\u043d\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HUSER.U_PASS IS '\u043f\u0430\u0440\u043e\u043b\u0430 \u0437\u0430 \u0432\u043b\u0438\u0437\u0430\u043d\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HUSER.USER_ID IS '\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b'");
	
			DB.ddlQuery(conn, "INSERT INTO HUSER VALUES (1, '\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440', 'Admin', '', 65535)");
		}
	}

	protected static void createContactsTypes(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HTYPE_DESC")) {
			DB.ddlQuery(conn, "CREATE table if not exists HTYPE_DESC"
					+ "("
					+ "	TYPE_ID int not null primary key hash,"
					+ "	TYPE_NAME varchar_ignorecase not null"
					+ ")");
			DB.ddlQuery(conn, "COMMENT ON TABLE HTYPE_DESC IS '\u0422\u0438\u043f\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HTYPE_DESC.TYPE_ID IS '\u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 (\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u043d\u043e\u043c\u0435\u0440)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HTYPE_DESC.TYPE_NAME IS '\u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 (\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435)'");
	
			DB.ddlQuery(conn, "INSERT INTO HTYPE_DESC(TYPE_ID, TYPE_NAME) VALUES " + 
					"(1, '\u0414\u043e\u0441\u0442\u0430\u0432\u0447\u0438\u043a')," + 
					"(2, '\u041a\u043b\u0438\u0435\u043d\u0442')");
		}
	}

	protected static void createContactsTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HCUSTOMER")) {
			DB.ddlQuery(conn, "CREATE table if not exists HCUSTOMER"
					+ "("
					+ "	CUSTOMER_ID int not null primary key hash,"
					+ "	TYPE_ID int,"
					+ "	C_NAME varchar_ignorecase,"
					+ "	C_BULSTAT varchar_ignorecase,"
					+ "	C_TAX varchar_ignorecase,"
					+ "	C_MOL varchar_ignorecase,"
					+ "	C_ADDRESS varchar_ignorecase,"
					+ "	C_CITY varchar_ignorecase,"
					+ "	C_CONTRY varchar_ignorecase,"
					+ "	C_BANK varchar_ignorecase,"
					+ "	C_BANKACC varchar_ignorecase,"
					+ "	C_DDS boolean DEFAULT false,"
					+ "	C_DELETED boolean DEFAULT false,"
					+ "	C_EMAIL varchar_ignorecase,"
					+ "	C_FAX varchar_ignorecase,"
					+ "	C_NOTE1 varchar_ignorecase,"
					+ "	C_NOTE2 varchar_ignorecase,"
					+ "	C_TEL varchar_ignorecase,"
					+ "	SEARCHTEXT varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HCUSTOMER_DEL_IX ON HCUSTOMER(C_DELETED)");
			// DB.ddlQuery(conn,
			// "CALL FT_CREATE_INDEX('PUBLIC', 'HCUSTOMER', 'SEARCHTEXT');");
			DB.ddlQuery(conn, "COMMENT ON TABLE HCUSTOMER IS '\u0422\u0430\u0431\u043b\u0438\u0446\u0430\u0442\u0430 \u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f\u0442\u0430 \u0437\u0430 \u0432\u0441\u044f\u043a\u0430 \u0435\u0434\u043d\u0430 \u043e\u0442 \u0444\u0438\u0440\u043c\u0438\u0442\u0435 \u043a\u043e\u0438\u0442\u043e \u0438\u0437\u0432\u044a\u0440\u0448\u0432\u0430\u0442 \u0434\u0435\u0439\u043d\u043e\u0441\u0442 \u0441 \u0441\u043a\u043b\u0430\u0434\u0430. \u041f\u043e\u043b\u0435\u0442\u043e TYPE_ID \u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0442\u0438\u043f\u0430 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430 (\u0414\u043e\u0441\u0442\u0430\u0432\u0447\u0438\u043a,\u0442\u044a\u0440\u0433\u043e\u0432\u0435\u0446,\u0441\u0435\u0440\u0432\u0438\u0437, \u0447\u0430\u0441\u0442\u043d\u043e \u043b\u0438\u0446\u0435 \u0438 \u0442.\u043d. / \u0432\u0438\u0436 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 TYPE_DESC)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_ADDRESS IS '\u0410\u0434\u0440\u0435\u0441'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_BANK IS '\u0411\u0430\u043d\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_BANKACC IS '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u043c\u0435\u0442\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_BULSTAT IS '\u0411\u0423\u041b\u0421\u0422\u0410\u0422 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u0435\u043d \u043d\u043e\u043c\u0435\u0440'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_CITY IS '\u0413\u0440\u0430\u0434'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_CONTRY IS '\u0441\u0442\u0440\u0430\u043d\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_DDS IS '\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0414\u0414\u0421'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_DELETED IS '\u0434\u0430\u043b\u0438 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u044a\u0442 \u0435 \u0438\u0441\u0442\u0440\u0438\u0442'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_EMAIL IS '\u0435-\u043c\u0430\u0438\u043b \u0437\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0438'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_FAX IS '\u0444\u0430\u043a\u0441 \u043d\u043e\u043c\u0435\u0440'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_MOL IS '\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043d\u043e \u043e\u0442\u0433\u043e\u0432\u043e\u0440\u043d\u043e \u043b\u0438\u0446\u0435 \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_NAME IS '\u0438\u043c\u0435 \u043d\u0430 \u0424\u0438\u0440\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_NOTE1 IS '\u0421\u043b\u0443\u0436\u0435\u0431\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_NOTE2 IS '\u0417\u0430\u0431\u0435\u043b\u0435\u0436\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_TAX IS '\u0414\u0430\u043d\u044a\u0447\u0435\u043d \u043d\u043e\u043c\u0435\u0440'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.C_TEL IS '\u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0437\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0438'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.CUSTOMER_ID IS '\u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u0430 (\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.TYPE_ID IS '\u0442\u0438\u043f \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u0430 (\u0432\u0438\u0436 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 TYPE_DESC)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCUSTOMER.SEARCHTEXT IS '\u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0433\u0440\u0443\u043f\u0438\u0440\u0430\u043d \u0442\u0435\u043a\u0441\u0442 \u0437\u0430 \u0442\u044a\u0440\u0441\u0435\u043d\u0435'");

			DB.ddlQuery(conn,
					"INSERT INTO HCUSTOMER(CUSTOMER_ID,TYPE_ID,C_NAME,C_MOL,C_CITY,C_CONTRY,C_EMAIL,C_TEL, SEARCHTEXT) VALUES"
							+ "(0, 1, '\u0412\u0430\u0448\u0430\u0442\u0430 \u0424\u0438\u0440\u043c\u0430', '\u0412\u0430\u0448\u0438\u044f\u0442 \u041c\u041e\u041b', '', '',"
							+ "'\u0412\u0430\u0448\u0438\u044f\u0442 \u0435-\u043c\u0435\u0439\u043b', '\u0412\u0430\u0448\u0438\u044f\u0442 \u0442\u0435\u043b\u0435\u0444\u043e\u043d', '')");
			DB.ddlQuery(
					conn,
					"INSERT INTO HCUSTOMER(CUSTOMER_ID,TYPE_ID,C_NAME,C_MOL,C_CITY,C_CONTRY,C_EMAIL,C_TEL, SEARCHTEXT) VALUES"
							+ "(1, 1, 'Dragon LTD', '\u0414\u0440\u0430\u0433\u043e\u043c\u0438\u0440 \u0414\u0438\u043c\u0438\u0442\u0440\u043e\u0432', '\u0421\u043e\u0444\u0438\u044f', '\u0411\u044a\u043b\u0433\u0430\u0440\u0438\u044f',"
							+ "'dragonltd@gmail.com', '+359 882 421 979', 'Dragon LTD \u0414\u0440\u0430\u0433\u043e\u043c\u0438\u0440 \u0414\u0438\u043c\u0438\u0442\u0440\u043e\u0432')");
		}
	}

	protected static void createCustomerComments(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HCOMMMENT")) {
			DB.ddlQuery(conn, "CREATE table if not exists HCOMMMENT"
					+ "("
					+ "	CUSTOMER_ID int not null,"
					+ "	USER_ID int not null,"
					+ "	C_DATE datetime not null,"
					+ "	C_COMMENT varchar_ignorecase not null"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HCOMMMENT_IX ON HCOMMMENT(CUSTOMER_ID)");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HCOMMMENT_DATE_IX ON HCOMMMENT(C_DATE)");
			DB.ddlQuery(
					conn,
					"COMMENT ON TABLE HCOMMMENT IS '\u0421\u044a\u0434\u044a\u0440\u0436\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f\u0442\u0430 \u0437\u0430 \u0437\u0430\u0431\u0435\u043b\u0435\u0436\u043a\u0438\u0442\u0435 \u043a\u043e\u0438\u0442\u043e \u0441\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u0435\u043d\u0438 \u043e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b \u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430 \u0437\u0430 \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCOMMMENT.CUSTOMER_ID IS '\u041a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 \u043a\u044a\u043c \u043a\u043e\u0433\u043e\u0442\u043e \u0435 \u0437\u0430\u0431\u0435\u043b\u0435\u0436\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCOMMMENT.USER_ID IS '\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b \u0441\u044a\u0437\u0434\u0430\u043b \u0437\u0430\u0431\u0435\u043b\u0435\u0436\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCOMMMENT.C_DATE IS '\u0434\u0430\u0442\u0430 \u043d\u0430 \u0432\u044a\u0432\u0435\u0436\u0434\u0430\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HCOMMMENT.C_COMMENT IS '\u0417\u0430\u0431\u0435\u043b\u0435\u0436\u043a\u0430 \u043e\u0442\u043d\u043e\u0441\u0442\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u0430'");
		}
	}

	protected static void createStockGroups(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HSTOCKGROUP")) {
			DB.ddlQuery(conn, "CREATE table if not exists HSTOCKGROUP"
					+ "("
					+ "	GROUP_ID int not null primary key hash,"
					+ "	GROUP_NAME varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "COMMENT ON TABLE HSTOCKGROUP IS '\u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0438\u043c\u0435\u043d\u0430\u0442\u0430 \u043d\u0430 \u0441\u0442\u043e\u043a\u043e\u0432\u0438\u0442\u0435 \u0433\u0440\u0443\u043f\u0438'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCKGROUP.GROUP_ID IS '\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u0442\u043e\u043a\u043e\u0432\u0430 \u0433\u0440\u0443\u043f\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCKGROUP.GROUP_NAME IS '\u0438\u043c\u0435 \u043d\u0430 \u0441\u0442\u043e\u043a\u043e\u0432\u0430 \u0433\u0440\u0443\u043f\u0430'");
		}
	}

	protected static void createStockTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HSTOCK")) {
			DB.ddlQuery(conn, "CREATE table if not exists HSTOCK"
					+ "("
					+ "	GROUP_ID int not null,"
					+ "	STOCK_ID int not null primary key hash,"
					+ "	STOCK_CODE varchar_ignorecase,"
					+ "	STOCK_NAME varchar_ignorecase,"
					+ "	SEARCHTEXT varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HSTOCK_GROUP_IX ON HSTOCK(GROUP_ID)");
			DB.ddlQuery(conn, "COMMENT ON TABLE HSTOCK IS '\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0438\u043c\u0435\u043d\u0430\u0442\u0430 \u043d\u0430 \u0441\u0442\u043e\u043a\u0438\u0442\u0435, \u0441\u044a\u043e\u0442\u0432\u0435\u0442\u0435\u043d \u0431\u0430\u0440 \u043a\u043e\u0434 \u0438 \u0441\u0442\u043e\u043a\u043e\u0432\u0430 \u0433\u0440\u0443\u043f\u0430 \u043a\u044a\u043c \u043a\u043e\u044f\u0442\u043e \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCK.GROUP_ID IS '\u0441\u0442\u043e\u043a\u043e\u0432\u0430 \u0433\u0440\u0443\u043f\u0430 \u043a\u044a\u043c \u043a\u043e\u044f\u0442\u043e \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCK.STOCK_CODE IS '\u0411\u0430\u0440 \u043a\u043e\u0434 \u043d\u0430 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCK.STOCK_ID IS '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u0442\u043e\u043a\u0430 (\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCK.STOCK_NAME IS '\u0438\u043c\u0435 \u043d\u0430 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTOCK.SEARCHTEXT IS '\u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0433\u0440\u0443\u043f\u0430\u0442\u0430 \u0438\u043c\u0435\u0442\u043e \u0438 \u0431\u0430\u0440\u043a\u043e\u0434\u0430 \u043a\u0430\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u0437\u0430 \u0442\u044a\u0440\u0441\u0435\u043d\u0435'");
		}
	}

	protected static void createGroupingStocks(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HGROUPING")) {
			DB.ddlQuery(conn, "CREATE table if not exists HGROUPING"
					+ "("
					+ "	GROUP_ID int not null,"// existing STOCK_ID
					+ "	STOCK_ID int not null,"
					+ "	QTY int not null"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HGROUPING_IX ON HGROUPING(GROUP_ID)");
			DB.ddlQuery(
					conn,
					"COMMENT ON TABLE HGROUPING IS '\u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0437\u0430 \u0441\u044a\u0441\u0442\u0430\u0432\u043d\u0438\u0442\u0435 \u0430\u0440\u0442\u0438\u043a\u0443\u043b\u0438 ( \u0430\u0440\u0442\u0438\u043a\u0443\u043b\u0438 \u043a\u043e\u0438\u0442\u043e \u043c\u043e\u0433\u0430\u0442 \u0434\u0430 \u0441\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u044f\u0442 \u043e\u0442 \u043d\u0430\u043b\u0438\u0447\u043d\u0438\u0442\u0435 \u0430\u0440\u0442\u0438\u043a\u0443\u043b\u0438) = \u0413\u0420\u0423\u041f\u0418\u0420\u0410\u041d\u0415.'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HGROUPING.GROUP_ID IS '\u0441\u044a\u0441\u0442\u0430\u0432\u043d\u0430 \u0441\u0442\u043e\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HGROUPING.QTY IS '\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430 \u0441\u044a\u0441\u0442\u0430\u0432\u044f\u0449\u0430 \u0441\u0442\u043e\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HGROUPING.STOCK_ID IS '\u0441\u044a\u0441\u0442\u0430\u0432\u044f\u0449\u0430 \u0441\u0442\u043e\u043a\u0430'");
		}
	}

	protected static void createStoreDesc(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HSTORE_DESC")) {
			DB.ddlQuery(conn, "CREATE table if not exists HSTORE_DESC"
					+ "("
					+ "	STORE_ID int not null primary key hash,"
					+ "	STORE_NAME varchar_ignorecase not null"
					+ ")");
			DB.ddlQuery(conn, "COMMENT ON TABLE HSTORE_DESC IS '\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u043e\u0432\u0435\u0442\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE_DESC.STORE_ID IS '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434 (\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE_DESC.STORE_NAME IS '\u0438\u043c\u0435 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434'");
			
			DB.ddlQuery(conn, "INSERT INTO HSTORE_DESC(STORE_ID, STORE_NAME) VALUES " + 
					"(1, '\u0421\u043a\u043b\u0430\u0434 1')," + 
					"(2, '\u0421\u043a\u043b\u0430\u0434 2')");
		}
	}

	protected static void createStoreTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HSTORE")) {
			DB.ddlQuery(conn, "CREATE table if not exists HSTORE"
					+ "("
					+ "	ROW_ID int not null primary key hash,"
					+ "	STORE_ID int not null,"
					+ "	STOCK_ID int not null,"
					+ "	CUSTOMER_ID int not null,"
					+ "	PRICE_BUY double not null,"
					+ "	PRICE_SELL double not null,"
					+ "	QTY int not null,"
					+ "	METRIC varchar_ignorecase not null,"
					+ "	DELIVERY_DATE datetime not null"
					+ ")");
			DB.ddlQuery(conn, "CREATE hash INDEX IF NOT EXISTS HSTORE_IX ON HSTORE(STORE_ID)");
			DB.ddlQuery(conn, "COMMENT ON TABLE HSTORE IS '\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0446\u044f\u043b\u0430\u0442\u0430 \u0441\u0442\u043e\u043a\u043e\u0432\u0430\u0442\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u043e\u0441\u0442 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.CUSTOMER_ID IS '\u041a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.DELIVERY_DATE IS '\u0434\u0430\u0442\u0430 \u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.METRIC IS '\u043c\u0435\u0440\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.PRICE_BUY IS '\u0426\u0435\u043d\u0430 \u043d\u0430 \u0437\u0430\u043a\u0443\u043f\u0443\u0432\u0430\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.PRICE_SELL IS '\u043f\u0440\u0435\u043f\u043e\u0440\u044a\u0447\u0438\u0442\u0435\u043b\u043d\u0430 \u0446\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.QTY IS '\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.STOCK_ID IS '\u0441\u0442\u043e\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSTORE.STORE_ID IS '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u043a\u043b\u0430\u0434 (\u0432\u0438\u0436 STORE_DESC)'");
		}
	}

	protected static void createInvoiceTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HINVOICE")) {
			return;
		}
		DB.ddlQuery(conn, "CREATE table if not exists HINVOICE"
				+ "("
				+ "	SALE_ID int not null primary key hash,"
				+ "	CUSTOMER_ID int not null,"
				+ "	INVOICE_NUMBER int not null,"
				+ "	INVOICE_TYPE int not null,"
				+ "	PAY_TYPE int not null,"
				+ "	SALE_DATE datetime not null,"
				+ "	USER_ID int not null"
				+ ")");
		DB.ddlQuery(conn, "CREATE HASH INDEX IF NOT EXISTS HINVOICE_CUSTOMER_IX ON HINVOICE(CUSTOMER_ID)");
		DB.ddlQuery(conn, "CREATE HASH INDEX IF NOT EXISTS HINVOICE_TYPE_IX ON HINVOICE(INVOICE_TYPE)");
		DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HINVOICE_DATE_IX ON HINVOICE(SALE_DATE)");
		DB.ddlQuery(
				conn,
				"COMMENT ON TABLE HINVOICE IS '\u0412\u0441\u0438\u0447\u043a\u0438 \u0440\u0430\u0437\u043f\u0438\u0441\u043d\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438 \u043a\u043e\u0438\u0442\u043e \u0441\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0430\u043d\u0438 \u043e\u0442 \u0441\u043a\u043b\u0430\u0434\u043e\u0432\u0430\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0430 (\u041d\u043e\u0440\u043c\u0430\u043b\u043d\u0430 \u0444\u0430\u043a\u0442\u0443\u0440\u0430, \u043e\u043f\u0440\u043e\u0441\u0442\u0435\u043d\u0430 \u0444\u0430\u043a\u0442\u0443\u0440\u0430, \u0435\u043a\u0441\u043f\u0435\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0430 \u0431\u0435\u043b\u0435\u0436\u043a\u0430)'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.CUSTOMER_ID IS '\u041a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 \u043d\u0430 \u043a\u043e\u0433\u043e\u0442\u043e \u0435 \u043f\u0440\u043e\u0434\u0430\u0434\u0435\u043d\u043e'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.INVOICE_NUMBER IS '\u041d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.INVOICE_TYPE IS '\u0442\u0438\u043f \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 (\u0444\u0430\u043a\u0442\u0443\u0440\u0430, \u0435\u043a\u0441\u043f. \u0431\u0435\u043b\u0435\u0436\u043a\u0430)'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.PAY_TYPE IS '\u041d\u0430\u0447\u0438\u043d \u043d\u0430 \u043f\u043b\u0430\u0449\u0430\u043d\u0435'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.SALE_DATE IS '\u0434\u0430\u0442\u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430\u0442\u0430'");
		DB.ddlQuery(conn,
				"COMMENT ON COLUMN HINVOICE.SALE_ID IS '\u041d\u043e\u043c\u0435\u0440 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430\u0442\u0430 (\u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d, \u0437\u0430 \u0432\u044a\u0442\u0440\u0435\u0448\u043d\u0430 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0430)'");
		DB.ddlQuery(conn, "COMMENT ON COLUMN HINVOICE.USER_ID IS '\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b \u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0430\u043b \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430\u0442\u0430'");
	}

	protected static void createSaleTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HSALE")) {
			DB.ddlQuery(conn, "CREATE table if not exists HSALE"
					+ "("
					+ "	SALE_ID int not null,"
					+ "	ROWID int not null,"
					+ "	CUSTOMER_ID int not null,"
					+ "	STORE_ID int not null,"
					+ "	STOCK_ID int not null,"
					+ "	DELIVERY_DATE datetime,"
					+ "	METRIC varchar_ignorecase,"
					+ "	PRICE_BUY double,"
					+ "	PRICE_SELL double,"
					+ "	QTY int,"
					+ "	SERIAL_NUMBER varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HSALE_IX ON HSALE(SALE_ID)");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HSALE_CUSTOMER_IX ON HSALE(CUSTOMER_ID)");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HSALE_STOCK_IX ON HSALE(STOCK_ID)");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HSALE_DATE_IX ON HSALE(DELIVERY_DATE)");
			DB.ddlQuery(conn, "COMMENT ON TABLE HSALE IS '\u0421\u043f\u0438\u0441\u044a\u043a \u0441 \u0441\u0442\u043e\u043a\u0438\u0442\u0435 \u043a\u043e\u0438\u0442\u043e \u0443\u0447\u0430\u0441\u0442\u0432\u0430\u0442 \u0432\u044a\u0432 \u0432\u0441\u044f\u043a\u0430 \u0435\u0434\u043d\u0430 \u043e\u0442 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0438\u0442\u0435.'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.CUSTOMER_ID IS '\u0414\u043e\u0441\u0442\u0430\u0432\u0447\u0438\u043a \u043d\u0430 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.DELIVERY_DATE IS '\u0434\u0430\u0442\u0430 \u043d \u0434\u043e\u0441\u0442\u0430\u0432\u044f\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.METRIC IS '\u043c\u0435\u0440\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.PRICE_BUY IS '\u0446\u0435\u043d\u0430 \u043d\u0430 \u0437\u0430\u043a\u043e\u043f\u0443\u0432\u0430\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.PRICE_SELL IS '\u0446\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.QTY IS '\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.SALE_ID IS '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0431\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.SERIAL_NUMBER IS '\u0421\u0435\u0440\u0438\u0435\u043d \u043d\u043e\u043c\u0435\u0440/\u0441\u043b\u0443\u0436\u0435\u0431\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u2013 \u0438\u0437\u043f\u043e\u043b\u0437\u0432\u0430 \u0441\u0435 \u043f\u0440\u0438 \u0433\u0430\u0440\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u0438\u0442\u0435 \u043a\u0430\u0440\u0442\u0438'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.STOCK_ID IS '\u0441\u0442\u043e\u043a\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HSALE.STORE_ID IS '\u0441\u043a\u043b\u0430\u0434'");
		}
	}

	protected static void createDestoredTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HDESTORED")) {
			DB.ddlQuery(conn, "CREATE table if not exists HDESTORED"
					+ "("
					+ "	ROW_ID int not null,"
					+ "	STORE_ID int not null,"
					+ "	STOCK_ID int not null,"
					+ "	CUSTOMER_ID int not null,"
					+ "	DELIVERY_DATE datetime not null,"
					+ "	PRICE_BUY double,"
					+ "	PRICE_SELL double,"
					+ "	QTY int,"
					+ "	METRIC varchar_ignorecase not null,"
					+ "	USER_ID int not null,"
					+ "	REASON varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "CREATE INDEX IF NOT EXISTS HDESTORED_IX ON HDESTORED(DELIVERY_DATE)");
			DB.ddlQuery(
					conn,
					"COMMENT ON TABLE HDESTORED IS '\u0422\u0430\u0431\u043b\u0438\u0446\u0430\u0442\u0430 \u0441\u044a\u0434\u044a\u0440\u0436\u0430 \u0432\u0441\u0438\u0447\u043a\u0438 \u0430\u0440\u0442\u0438\u043a\u0443\u043b\u0438 \u043a\u043e\u0438\u0442\u043e \u0441\u0430 \u0431\u0438\u043b\u0438 \u0432\u044a\u0432\u0435\u0434\u0435\u043d\u0438 \u0432 \u0441\u043a\u043b\u0430\u0434\u0430 \u0438 \u0441\u0430 \u0431\u0438\u043b\u0438 \u043e\u0442\u043f\u0438\u0441\u0430\u043d\u0438 (\u0440\u0430\u0437\u043f\u0438\u0441\u0430\u043d\u0438 \u0431\u0435\u0437 \u0434\u0430 \u0441\u0430 \u043f\u0440\u043e\u0434\u0430\u0434\u0435\u043d\u0438 - \u0433\u0440\u0435\u0448\u043d\u043e \u0432\u044a\u0432\u0435\u0434\u0435\u043d\u0438 \u0430\u0440\u0442\u0438\u043a\u0443\u043b\u0438, \u043f\u0440\u0435\u043c\u0435\u0441\u0442\u0435\u043d\u0438 \u0431\u0435\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438, \u0433\u0440\u0435\u0448\u043a\u0430 \u0432 \u0431\u0440\u043e\u0439\u043a\u0430\u0442\u0430 \u0438\u043b\u0438 \u0432 \u043d\u044f\u043a\u043e\u0438 \u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0430\u0440\u0442\u0438\u043a\u0443\u043b)'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.CUSTOMER_ID IS '\u041a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442 \u043e\u0442 \u043a\u043e\u0439\u0442\u043e \u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u0435\u043d\u0430 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.DELIVERY_DATE IS '\u0434\u0430\u0442\u0430 \u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0432\u044f\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.METRIC IS '\u043c\u0435\u0440\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.PRICE_BUY IS '\u0446\u0435\u043d\u0430 \u043d\u0430 \u0437\u0430\u043a\u043e\u043f\u0443\u0432\u0430\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.PRICE_SELL IS '\u0446\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043d\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.QTY IS '\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.REASON IS '\u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0437\u0430 \u043e\u0442\u043f\u0438\u0441\u0432\u0430\u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.STOCK_ID IS '\u0441\u0442\u043e\u043a\u0430 \u043a\u043e\u044f\u0442\u043e \u0435 \u043e\u0442\u043f\u0438\u0441\u0430\u043d\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.STORE_ID IS '\u0441\u043a\u043b\u0430\u0434 \u043e\u0442 \u043a\u044a\u0434\u0435\u0442\u043e \u0435 \u043e\u0442\u043f\u0438\u0441\u0430\u043d\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HDESTORED.USER_ID IS '\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b \u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0430 \u043e\u0442\u043f\u0438\u0441\u0430\u043b \u0441\u0442\u043e\u043a\u0430\u0442\u0430'");
		}
	}

	protected static void createSettingsTable(HashSet<String> schemaTables, DBManager DB, Connection conn) {
		if (!schemaTables.contains("HEDRON_SETTINGS")) {
			DB.ddlQuery(conn, "CREATE table if not exists HEDRON_SETTINGS"
					+ "("
					+ "	S_NAME varchar_ignorecase not null primary key hash,"
					+ "	S_DESC varchar_ignorecase not null,"
					+ "	S_VALUE varchar_ignorecase"
					+ ")");
			DB.ddlQuery(conn, "COMMENT ON TABLE HEDRON_SETTINGS IS '\u0421\u044a\u0434\u044a\u0440\u0436\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0438\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HEDRON_SETTINGS.S_NAME IS '\u0418\u043c\u0435 \u043d\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0442\u0430'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HEDRON_SETTINGS.S_DESC IS '\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u043e\u0439\u043d\u043e\u0441\u0442\u0442\u0430 \u043a\u043e\u044f\u0442\u043e \u0442\u0440\u044f\u0431\u0432\u0430 \u0434\u0430 \u0441\u0435 \u0437\u0430\u0434\u0430\u0434\u0435'");
			DB.ddlQuery(conn, "COMMENT ON COLUMN HEDRON_SETTINGS.S_VALUE IS '\u0441\u0442\u043e\u0439\u043d\u043e\u0441\u0442 \u043d\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0442\u0430'");
			
			DB.ddlQuery(conn,
					"INSERT INTO HEDRON_SETTINGS(S_NAME, S_DESC, S_VALUE) VALUES"
					+"('company.address', '\u0410\u0434\u0440\u0435\u0441 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430', ''),"
					+"('company.bank', '\u0431\u0430\u043d\u043a\u0430 \u0432 \u043a\u043e\u044f\u0442\u043e \u0444\u0438\u0440\u043c\u0430\u0442\u0430 \u0438\u043c\u0430 \u0441\u043c\u0435\u0442\u043a\u0430', ''),"
					+"('company.bank.account', '\u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0441\u043c\u0435\u0442\u043a\u0430 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430 \u0432\u044a\u0432 \u0431\u0430\u043d\u043a\u0430 ''company.BANK''', ''),"
					+"('company.bulstat', '\u0411\u0423\u041b\u0421\u0422\u0410\u0422 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u0435\u043d \u043d\u043e\u043c\u0435\u0440 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430', ''),"
					+"('company.city', '\u0413\u0440\u0430\u0434 \u0432 \u043a\u043e\u0439\u0442\u043e \u0441\u0435 \u043d\u0430\u043c\u0438\u0440\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430', ''),"
					+"('company.country', '\u0421\u0442\u0440\u0430\u043d\u0430', ''),"
					+"('company.currency', '\u0421\u044a\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0430\u043b\u0443\u0442\u0430\u0442\u0430 \u043a\u043e\u044f\u0442\u043e \u0449\u0435 \u0441\u0435 \u043f\u043e\u043b\u0437\u0432\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0430\u0442\u0430 (\u043b\u0432, $ ...)', ''),"
					+"('company.vat', '\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0430\u043d\u0430 \u043b\u0438 \u0435 \u0444\u0438\u0440\u043c\u0430\u0442\u0430 \u0437\u0430 \u0414\u0414\u0421', ''),"
					+"('company.email', '\u0435-\u043c\u0430\u0438\u043b \u0437\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0438', ''),"
					+"('company.fax', '\u0444\u0430\u043a\u0441 \u0437\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0438', ''),"
					+"('company.mol', '\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043d\u043e \u043e\u0442\u0433\u043e\u0432\u043e\u0440\u043d\u043e \u043b\u0438\u0446\u0435', ''),"
					+"('company.name', '\u0438\u043c\u0435 \u043d\u0430 \u0444\u0438\u0440\u043c\u0430\u0442\u0430 \u043f\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f', ''),"
					+"('company.tax.id', '\u0414\u0430\u043d\u044a\u0447\u0435\u043d \u043d\u043e\u043c\u0435\u0440', ''),"
					+"('company.telephone', '\u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0437\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0438', ''),"
					+"('invoice.warranty', 'HTML \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0430\u043d \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u0438\u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438', '')");
		}
	}
}
